package cn.supermaster.management.web.service.monitor.impl;

import cn.supermaster.management.common.page.TableDataInfo;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.common.utils.WebHelper;
import cn.supermaster.management.common.utils.poi.ExcelUtil;
import cn.supermaster.management.core.component.PasswordManager;
import cn.supermaster.management.system.domain.SysLogininfor;
import cn.supermaster.management.system.service.ISystemLoginInformationService;
import cn.supermaster.management.web.service.monitor.IMonitorLoginInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.service.monitor.impl
 * @ClassName: MonitorLoginInformationServiceImpl
 * @Description: [系统访问记录]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/10 18:08
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Service
public class MonitorLoginInformationServiceImpl implements IMonitorLoginInformationService {

    private String prefix = "monitor/logininfor";

    @Autowired
    private ISystemLoginInformationService logininforService;

    @Autowired
    private PasswordManager passwordService;

    /*
     * ================================================
     *  页面跳转功能实现
     * ================================================
     */

    /**
     * @Description: [跳转登录信息界面]
     * <p></P>
     * @Title: skipLoginInformationView
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Return: java.lang.String
     */
    @Override
    public String skipLoginInformationView() {
        return prefix + "/logininfor";
    }


    /*
     * ================================================
     *  Rest功能实现
     * ================================================
     */
    @Override
    public TableDataInfo queryLoginInformationList(SysLogininfor loginInfo) {
        WebHelper.startPage();
        List<SysLogininfor> list = logininforService.selectLogininforList(loginInfo);
        TableDataInfo dataTable = WebHelper.getDataTable(list);
        //
        return dataTable;
    }

    /**
     * @param loginInfo
     * @Description: [导出用户登录信息列表]
     * <p></P>
     * @Title: doExportLoginInformation
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: loginInfo
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse doExportLoginInformation(SysLogininfor loginInfo) {
        List<SysLogininfor> list = logininforService.selectLogininforList(loginInfo);
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
        WebResponse reult = util.exportExcel(list, "登录日志");
        //
        return reult;
    }

    /**
     * @param ids
     * @Description: [删除登录日志]
     * <p></P>
     * @Title: doRemoveLoginInformation
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: ids
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse doRemoveLoginInformation(String ids) {
        int rows = logininforService.deleteLogininforByIds(ids);
        WebResponse result = WebHelper.webResult(rows);
        //
        return result;
    }

    /**
     * @Description: [清空登录日志]
     * <p></P>
     * @Title: doCleanLoginInformation
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Return: void
     * @Throws:
     */
    @Override
    public WebResponse doCleanLoginInformation() {
        logininforService.cleanLogininfor();
        //
        return WebHelper.success();
    }

    /**
     * @Description: [账户信息解锁]
     * <p></P>
     * @Title: doUnlockAccount
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: userName
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse doUnlockAccount(String userName) {
        passwordService.cleanLoginRecordCache(userName);
        return WebHelper.success();
    }
}